<?php
/**
* Page is put together
*
* Based on the side path the content with header, navigation
* etc. is loaded and is issued as a page
*
* @author Mario Schillermann <info@rockit-flash.com>
* @encoding UTF-8 äöüßÖÄÜ
* @copyright © 2011 Mario Schillermann (info@rockit-flash.com)
* @license GNU GPL v2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
* @package Page
* @subpackage Index
* @link $HeadURL$
* @version SVN: $Id$
* @phpVersion >=5
* @todo 'content-type' muss in die ini Datei
*/

class Page_IndexController extends Zend_Controller_Action
{
    /**
     * Initialize the general options
     * 
     * @return void
     */
    public function init()
    {
        $this->view->headMeta()->appendHttpEquiv('content-type', 'text/html;charset=utf-8');
        $this->view->headMeta()->appendName('x-release-version','0.1.0');
    }
    /**
     * Build the page with navi, content, footer etc.
     * 
     * @var string          $courseRequest   course
     * @var string          $languageRequest language
     * @var string          $pagePath        created real page path
     * @var string          $renderPath      path to render
     * @var string          $metaFile        path to meta file data
     * @var Zend_Config_Ini $metaConfig      meta config data
     * @var array           $metaDatas       meta data
     * 
     * @return void
     */
    public function indexAction()
    {
        $this->_helper->actionStack('index','title');

        $courseRequest = $this->getRequest()->getParam('course');
        $languageRequest = $this->getRequest()->getParam('language');
        $pagePath = realpath(APPLICATION_PATH .  '/../page/' . $languageRequest . '/');

        if(empty($courseRequest)) {
            $renderPath = "index";
        }
        else {
            $course = new Page_Model_Course();
            $renderPath = $course->getRenderPath($courseRequest);
        }
        // <BEGIN> Wenn Meta Daten vorhanden sind werden sie ausgegeben
        if(is_file(($metaFile = $pagePath . '/' . $renderPath . '.meta'))) {

            $metaConfig = new Zend_Config_Ini($metaFile);
            $metaDatas = $metaConfig->toArray();
            
            foreach ($metaDatas as $metaTyp => $metaValue)
                $this->view->headMeta()->appendName($metaTyp, $metaValue);
        }
        // <END>
        
        $position = new Navi_Model_Position();

        $this->view->addScriptPath($pagePath);
        $this->view->course = $courseRequest;
        $this->view->breadcrumb = $position->get($courseRequest);
        $this->render($renderPath, null, true);
        $this->render('header', 'header', true);
        $this->render('navi', 'navi', true);
        $this->render('footer', 'footer', true);
        $this->render('teaser', 'teaser', true);
    }


}

